package org.csu.mypetstore.web.servlets;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HandleValidServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain");
        PrintWriter printWriter = response.getWriter();
        //获取用户输入的字符串
        String validString = request.getParameter("valistr");
        System.out.println(validString);
        //正确验证码
        String text = ValiImageServlet.text;
        System.out.println(text);
        //忽略大小写
        if(text.compareToIgnoreCase(validString)==0){
            printWriter.print("Right");
            System.out.println("this is right");
        }else{
            printWriter.print("Wrong");
            System.out.println("this is wrong");
        }

        printWriter.flush();
        printWriter.close();
    }
}
